package com.example.video.file_server.common.FFmpeg.domain.enums;

import com.example.video.file_server.common.FFmpeg.domain.VideoMetaInfo;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

@Getter
public enum DefinitionEnum {

    ONE_LEVEL("fluent",640,480,200),
    TWO_LEVEL("standard ",720,480,1024),
    THREE_LEVEL("high",1280,720,1024),
    FOUR_LEVELP("all_high",1920,1080,1024);

    private String sign;
    private Integer width;
    private Integer height;
    private Integer bitRate;
    private static List<DefinitionEnum> lowToHigh = new ArrayList<>();;

    static {
        lowToHigh.add(DefinitionEnum.ONE_LEVEL);
        lowToHigh.add(DefinitionEnum.TWO_LEVEL);
        lowToHigh.add(DefinitionEnum.THREE_LEVEL);
        lowToHigh.add(DefinitionEnum.FOUR_LEVELP);
    }

    DefinitionEnum(String sign, Integer width, Integer height, Integer bitRate){
        this.sign = sign;
        this.width= width;
        this.height = height;
        this.bitRate = bitRate;
    }

    public void setBitRate(Integer bitRate){
        this.bitRate = bitRate;
    }

    public static List<DefinitionEnum> filter(VideoMetaInfo info){
        List<DefinitionEnum> list = new ArrayList<>();
        for (DefinitionEnum level : lowToHigh){
            if (info.getBitRate() > level.bitRate && info.getWidth()>level.width && info.getHeight()>level.height){
                list.add(level);
            }else {
                if (list.size()<1){
                    list.add(ONE_LEVEL);
                }
            }
        }
        if (list.size() == 1 && info.getBitRate() > ONE_LEVEL.bitRate){
            list.get(0).setBitRate(info.getBitRate());
        }
        return list;
    }

}
